<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <script src="../lib/vue.js"></script>
  </head>

  <body>
    <div id="app">
      <cpn></cpn>
    </div>

    <template id="cpn">
      <div>
        <h2>我是子组件</h2>
        <button @click="btclick">点我获取父组件对象</button>
      </div>
    </template>
    <script>
      var vm = new Vue({
        el: '#app',
        data: {
          pname: '父组件名称是AA'
        },
        components: {
          cpn: {
            template: '#cpn',
            methods: {
              btclick() {
                //访问父组件
                console.log('我被点了')
                console.log(this.$parent)
                console.log(this.$parent.pname)
              }
            }
          }
        }
      })
    </script>
  </body>
</html>
